package br.com.gkarian.mydesk.conversores;

import java.text.MessageFormat;
import java.util.ResourceBundle;

import br.com.caelum.vraptor.Convert;
import br.com.caelum.vraptor.Converter;
import br.com.caelum.vraptor.converter.ConversionError;
import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.gkarian.mydesk.enums.TipoConta;

@Convert(TipoConta.class)
@ApplicationScoped
public class TipoContaConverter implements Converter<TipoConta> {

	@Override
	public TipoConta convert(String value, Class<? extends TipoConta> type,
			ResourceBundle bundle) {
		
		if (value == null || value.equals("")) {
			return null;
		}
		try {
			return TipoConta.recuperarValor(value);
		} catch (Exception e) {
			throw new ConversionError(MessageFormat.format(bundle.getString("aa"), value));
		}
	}
}
